#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2005;
const int MOD = 998244353;
int n, m, d;
char s[N][N];
ll a[N], b[N], c[N];
ll sum[N];
void solve() {
  cin >> n >> m >> d;
  rep(i, 1, n) rep(j, 1, m) cin >> s[i][j];
  rep(j, 1, m) {
    if (s[n][j] == 'X')
      a[j] = 1;
    else
      a[j] = 0;
  }
  rep(j, 1, m) sum[j] = (sum[j - 1] + a[j]) % MOD;
  rep(j, 1, m) {
    if (s[n][j] == 'X') {
      int l = max(1, j - d);
      int r = min(m, j + d);
      b[j] = (sum[r] - sum[l - 1] + MOD) % MOD;
    } else
      b[j] = 0;
  }
  rep(j, 1, m) sum[j] = (sum[j - 1] + b[j]) % MOD;
  per(i, n - 1, 1) {
    rep(j, 1, m) {
      if (s[i][j] == 'X') {
        int l = max(1, j - (d - 1));
        int r = min(m, j + (d - 1));
        a[j] = (sum[r] - sum[l - 1] + MOD) % MOD;
      } else
        a[j] = 0;
    }
    rep(j, 1, m) sum[j] = (sum[j - 1] + a[j]) % MOD;
    rep(j, 1, m) {
      if (s[i][j] == 'X') {
        int l = max(1, j - d);
        int r = min(m, j + d);
        b[j] = (sum[r] - sum[l - 1] + MOD) % MOD;
      } else
        b[j] = 0;
    }
    rep(j, 1, m) sum[j] = (sum[j - 1] + b[j]) % MOD;
  }
  cout << sum[m] << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}